<template>
    <div class="potoslist_contaiber">
        <!-- 顶部滑动子导航 begin -->
        <div id="slider" class="mui-slider ">
            <div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
                <div class="mui-scroll">
                    <a :class="['mui-control-item' , item.id === 0 ? 'mui-active' : '' ]" v-for="item in cates" :key="item.id" @tap="getimages(item.id)">
                        {{item.title}}
                    </a>
                </div>
            </div>
        </div>
        <!-- 顶部滑动子导航 end -->
        <!-- 图片加载 -->
        <ul class="potolist">
            <router-link v-for="item in list" :key="item.id" :to="'/home/potosinfo/'+ item.id " tag="li">
                <img v-lazy="item.img_url">
                <div class="potolist_info">
                    <h1>{{item.title}}</h1>
                    <p>{{item.zhaiyao}}</p>
                </div>
            </router-link>
        </ul>

    </div>
</template>

<script>
import mui from "../../lib/mui/js/mui.min.js";

export default {
    data() {
        return {
            cates: [],
            list: []
        };
    },
    created() {
        this.getImgCategory();
        this.getimages(0);
    },
    mounted() {
        mui(".mui-scroll-wrapper").scroll({
            deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
        });
    },
    methods: {
        // 图片列表
        getImgCategory() {
            this.$http.get("api/getimgcategory").then(result => {
                if (result.body.status === 0) {
                    var cmt = result.body.message.unshift({
                        title: "全部",
                        id: 0
                    });
                    this.cates = result.body.message;
                    console.log(this.cates);
                }
            });
        },
        // 滑动子导航
        getimages(catesId) {
            this.$http.get("api/getimages/" + catesId).then(result => {
                if (result.body.status === 0) {
                    this.list = result.body.message;
                } else {
                    Toast("获取图片失败！");
                }
            });
        }
    }
};
</script>

<style lang="scss">
* {
    touch-action: pan-y;
}
.potoslist_contaiber {
    .potolist {
        list-style: none;
        margin: 0;
        padding: 0;
        background-color: #f1f1f1;
        padding: 10px;
        padding-bottom: 0;
        li {
            position: relative;
            margin-bottom: 10px;
            box-shadow: 0 0 10px #666;
        }
        img {
            width: 100%;
            vertical-align: middle;
        }
        img[lazy="loading"] {
            width: 40px;
            height: 300px;
            margin: auto;
            display: block;
        }
        .potolist_info {
            padding: 0 5px;
            max-height: 84px;
            position: absolute;
            bottom: 0;
            background: rgba(0,0,0,0.4);
            color: #fff;
            overflow: hidden;
            h1 {
                font-size: 14px;
            }
            p{
                color: #fff;
                font-size: 12px;
            }
        }
    }
}
</style>
